package org.aeon.heroicsagatextedition.role.factory;

import org.aeon.heroicsagatextedition.role.product.RoleUnit;

import java.lang.reflect.InvocationTargetException;

/**
 * @projectName: HeroicSagaTextEdition
 * @package: org.aeon.heroicsagatextedition.role
 * @className: MonsterFactory
 * @author: MissingAeon
 * @date: 2023/12/22 14:38
 * @description: 怪物创建工厂
 * 利用反射创建需要的具体怪物类
 */
public class MonsterFactory implements RoleUnitFactory {
    @Override
    public RoleUnit createRoleUnit(String name) {
        try {
            return (RoleUnit) Class.forName("org.aeon.heroicsagatextedition.role.product.monster." + name)
                    .getDeclaredConstructor().newInstance();
        } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException |
                 IllegalAccessException ignored) {
            throw new RuntimeException("怪物创建错误！");
        }
    }
}
